package com.jf.springcloud.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2025-02-27
 * Time:23:22
 */
@RequestMapping("/breaker")
@RestController
public class CircuitBreakerController {
    private int slowCallNum = 0;
    private int exceptionNum = 0;
    @GetMapping("/slow_call_ratio")
    public String slowCallRatio() {
        if (slowCallNum++ % 3 == 0) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return "SlowCallRatio";
    }
    @GetMapping("/exception_ratio")
    public String exceptionRatio() {
        if (exceptionNum++ % 3 == 0) {
            int a = 1 / 0;
        }
        return "ExceptionRatio";
    }
    @GetMapping("/exception_num")
    public String exceptionNum(@RequestParam("state") Integer state) {
        if (state == 1) {
            int a = 1 / 0;
        }
        return "ExceptionNum";
    }
}
